<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>xrepo</title>
  <link rel="icon" href="/assets/img/favicon.ico">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="description" content="Description">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link href="//cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" rel="stylesheet">
  <style>
	.markdown-body {
		box-sizing: border-box;
		min-width: 200px;
		max-width: 980px;
		margin: 0 auto;
		padding: 45px;
	}

	@media (max-width: 767px) {
		.markdown-body {
			padding: 15px;
		}
	}
  </style>
</head>
<body>
<article class="markdown-body">
<h4>This is a mirror page, please see the original page: </h4><a href="https://xrepo.xmake.io/#/getting_started">https://xrepo.xmake.io/#/getting_started</a>
<div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
</br>
    <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
<style>
#carbonads {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

#carbonads {
  display: flex;
  max-width: 330px;
  background-color: hsl(0, 0%, 98%);
  box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
}

#carbonads a {
  color: inherit;
  text-decoration: none;
}

#carbonads a:hover {
  color: inherit;
}

#carbonads span {
  position: relative;
  display: block;
  overflow: hidden;
}

#carbonads .carbon-wrap {
  display: flex;
}

.carbon-img {
  display: block;
  margin: 0;
  line-height: 1;
}

.carbon-img img {
  display: block;
}

.carbon-text {
  font-size: 13px;
  padding: 10px;
  line-height: 1.5;
  text-align: left;
}

.carbon-poweredby {
  display: block;
  padding: 8px 10px;
  background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  font-size: 9px;
  line-height: 1;
}
</style>
    <h2 id="introduction">Introduction</h2>
<p>xrepo is a cross-platform C/C++ package manager based on <a href="https://github.com/xmake-io/xmake">Xmake</a>.</p>
<p>It is based on the runtime provided by xmake, but it is a complete and independent package management program. Compared with package managers such as vcpkg/homebrew, xrepo can provide C/C++ packages for more platforms and architectures at the same time.</p>
<p>And it also supports multi-version semantic selection. In addition, it is also a decentralized distributed repository. It not only provides the official <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a> repository, It also supports users to build multiple private repositorys.</p>
<p>At the same time, xrepo also supports installing packages from third-party package managers such as vcpkg/homebrew/conan, and provides unified and consistent library link information to facilitate integration and docking with third-party projects.</p>
<p>If you want to know more, please refer to: <a href="https://xmake.io/#/home">Documents</a>, <a href="https://github.com/xmake-io/xrepo">Github</a> and <a href="https://gitee.com/tboox/xrepo">Gitee</a></p>
<p><img src="https://github.com/xmake-io/xrepo-docs/raw/master/assets/img/xrepo.gif" alt=""></p>
<h2 id="installation">Installation</h2>
<p>We only need install xmake to use the xrepo command. About the installation of xmake, we can see: <a href="https://xmake.io/#/guide/installation">Xmake Installation Document</a>.</p>
<h2 id="supportedplatforms">Supported platforms</h2>
<ul>
<li>Windows (x86, x64)</li>
<li>macOS (i386, x86_64, arm64)</li>
<li>Linux (i386, x86_64, cross-toolchains ..)</li>
<li>*BSD (i386, x86_64)</li>
<li>Android (x86, x86_64, armeabi, armeabi-v7a, arm64-v8a)</li>
<li>iOS (armv7, armv7s, arm64, i386, x86_64)</li>
<li>MSYS (i386, x86_64)</li>
<li>MinGW (i386, x86_64, arm, arm64)</li>
<li>Cross Toolchains</li>
</ul>
<h2 id="supporydistributedrepository">Suppory distributed repository</h2>
<p>In addition to directly retrieving the installation package from the official repository: <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a>.</p>
<p>We can also add any number of self-built repositories, and even completely isolate the external network, and only maintain the installation and integration of private packages on the company&#39;s internal network.</p>
<p>Just use the following command to add your own repository address:</p>
<pre><code class="lang-console">$ xrepo add-repo myrepo https://github.com/mygroup/myrepo
</code></pre>
<h2 id="seamlessintegrationwithxmakeproject">Seamless integration with xmake project</h2>
<pre><code class="lang-lua">add_requires("tbox >1.6.1", "libuv master", "vcpkg::ffmpeg", "brew::pcre2/libpcre2-8")
add_requires("conan::openssl/1.1.1g", {alias = "openssl", optional = true, debug = true})
target("test")
     set_kind("binary")
     add_files("src/*.c")
     add_packages("tbox", "libuv", "vcpkg::ffmpeg", "brew::pcre2/libpcre2-8", "openssl")
</code></pre>
<p>The following is the overall architecture and compilation process integrated with xmake.</p>
<p><img src="https://xmake.io/assets/img/index/package_arch.png" width="650px" /></p>
<h2 id="getstarted">Get started</h2>
<h3 id="installationpackage">Installation package</h3>
<h4 id="basicusage">Basic usage</h4>
<pre><code class="lang-console">$ xrepo install zlib tbox
</code></pre>
<h4 id="installthespecifiedversionpackage">Install the specified version package</h4>
<pre><code class="lang-console">$ xrepo install "zlib 1.2.x"
$ xrepo install "zlib >=1.2.0"
</code></pre>
<h4 id="installthespecifiedplatformpackage">Install the specified platform package</h4>
<pre><code class="lang-console">$ xrepo install -p iphoneos -a arm64 zlib
$ xrepo install -p android [--ndk=/xxx] zlib
$ xrepo install -p mingw [--mingw=/xxx] zlib
$ xrepo install -p cross --sdk=/xxx/arm-linux-musleabi-cross zlib
</code></pre>
<h4 id="installthedebugpackage">Install the debug package</h4>
<pre><code class="lang-console">$ xrepo install -m debug zlib
</code></pre>
<h4 id="installthepackagewithdynamiclibrary">Install the package with dynamic library</h4>
<pre><code class="lang-console">$ xrepo install -k shared zlib
</code></pre>
<h4 id="installthespecifiedconfigurationpackage">Install the specified configuration package</h4>
<pre><code class="lang-console">$ xrepo install -f "vs_runtime=&#39;MD&#39;" zlib
$ xrepo install -f "regex=true,thread=true" boost
</code></pre>
<h4 id="installpackagesfromthirdpartypackagemanager">Install packages from third-party package manager</h4>
<pre><code class="lang-console">$ xrepo install brew::zlib
$ xrepo install vcpkg::zlib
$ xrepo install conan::zlib/1.2.11
</code></pre>
<h3 id="findthelibraryinformationofthepackage">Find the library information of the package</h3>
<pre><code class="lang-console">$ xrepo fetch pcre2
{
  {
    linkdirs = {
      "/usr/local/Cellar/pcre2/10.33/lib"
    },
    links = {
      "pcre2-8"
    },
    defines = {
      "PCRE2_CODE_UNIT_WIDTH=8"
    },
    includedirs = "/usr/local/Cellar/pcre2/10.33/include"
  }
}
</code></pre>
<pre><code class="lang-console">$ xrepo fetch --ldflags openssl
-L/Users/ruki/.xmake/packages/o/openssl/1.1.1/d639b7d6e3244216b403b39df5101abf/lib -lcrypto -lssl
</code></pre>
<pre><code class="lang-console">$ xrepo fetch --cflags openssl
-I/Users/ruki/.xmake/packages/o/openssl/1.1.1/d639b7d6e3244216b403b39df5101abf/include
</code></pre>
<pre><code class="lang-console">$ xrepo fetch -p [iphoneos|android] --cflags "zlib 1.2.x"
-I/Users/ruki/.xmake/packages/z/zlib/1.2.11/df72d410e7e14391b1a4375d868a240c/include
</code></pre>
<pre><code class="lang-console">$ xrepo fetch --cflags --ldflags conan::zlib/1.2.11
-I/Users/ruki/.conan/data/zlib/1.2.11/_/_/package/f74366f76f700cc6e991285892ad7a23c30e6d47/include -L/Users/ruki/.conan/data/zlib/1.2.11/_/_/package/f74366f76f700cc6e991285892ad7a23c30e6d47/lib -lz
</code></pre>
<h3 id="exporttheinstalledpackages">Export the installed packages</h3>
<p>xrepo can quickly export installed packages, including corresponding library files, header files, etc.</p>
<pre><code class="lang-console">$ xrepo export -o /tmp/output zlib
</code></pre>
<h3 id="searchsupportedpackages">Search supported packages</h3>
<pre><code class="lang-console">$ xrepo search zlib "pcr*"
    zlib:
      -> zlib: A Massively Spiffy Yet Delicately Unobtrusive Compression Library (in xmake-repo)
    pcr*:
      -> pcre2: A Perl Compatible Regular Expressions Library (in xmake-repo)
      -> pcre: A Perl Compatible Regular Expressions Library (in xmake-repo)
</code></pre>
<h3 id="showpackageenvironmentinformation">Show package environment information</h3>
<pre><code class="lang-console">$ xrepo env --show luajit
{
   OLDPWD = "/mnt/tbox",
   HOME = "/home/ruki",
   PATH = "/home/ruki/.xmake/packages/l/luajit/2.1.0-beta3/fbac76d823b844f0b91abf3df0a3bc61/bin:/tmp:/tmp/arm-linux-musleabi-cross/bin:~/.local/bin: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
   TERM = "xterm",
   PWD = "/mnt/xmake",
   XMAKE_PROGRAM_DIR = "/mnt/xmake/xmake",
   HOSTNAME = "e6edd61ff1ab",
   LD_LIBRARY_PATH = "/home/ruki/.xmake/packages/l/luajit/2.1.0-beta3/fbac76d823b844f0b91abf3df0a3bc61/lib",
   SHLVL = "1",
   _ = "/mnt/xmake/scripts/xrepo.sh"
}
</code></pre>
<h3 id="packagevirtualenvironment">Package virtual environment</h3>
<h4 id="enterthevirtualenvironment">Enter the virtual environment</h4>
<p>We can customize some package configurations by adding the xmake.lua file in the current directory, and then enter the specific package virtual environment.</p>
<pre><code class="lang-lua">add_requires("zlib 1.2.11")
add_requires("python 3.x", "luajit")
</code></pre>
<pre><code class="lang-console">$ xrepo env shell
> python --version
> luajit --version
</code></pre>
<p>We can also configure and load the corresponding toolchain environment in xmake.lua, for example, load the VS compilation environment.</p>
<pre><code class="lang-lua">set_toolchains("msvc")
</code></pre>
<h4 id="managevirtualenvironments">Manage virtual environments</h4>
<p>We can use the following command to register the specified virtual environment configuration globally to the system for quick switching.</p>
<pre><code class="lang-console">$ xrepo env --add /tmp/base.lua
</code></pre>
<p>At this time, we have saved a global virtual environment called base, and we can view it through the list command.</p>
<pre><code class="lang-console">$ xrepo env --list
/Users/ruki/.xmake/envs:
  -base
envs(1) found!
</code></pre>
<p>We can also delete it.</p>
<pre><code class="lang-console">$ xrepo env --remove base
</code></pre>
<h4 id="switchglobalvirtualenvironment">Switch global virtual environment</h4>
<p>If we register multiple virtual environments, we can also switch them quickly.</p>
<pre><code class="lang-console">$ xrepo env -b base shell
> python --version
</code></pre>
<p>Or directly load the specified virtual environment to run specific commands</p>
<pre><code class="lang-console">$ xrepo env -b base python --version
</code></pre>
<p><code>xrepo env -b/--bind</code> is to bind the specified virtual environment. For more details, see: <a href="https://github.com/xmake-io/xmake/issues/1762">#1762</a></p>
<h4 id="quickswitchingoftemporaryvirtualenvironments">Quick switching of temporary virtual environments</h4>
<p>Not only can we manage switching environments by configuring environment configuration files such as <code>myenv.lua</code>, but we can also specify a list of environment packages to bind to on the command line on an ad hoc basis, allowing for quick switching without any configuration.</p>
<p>For example, if we want to enter an environment with python 3.0, luajit and cmake, all we need to do is to execute</p>
<pre><code class="lang-console">$ xrepo env -b "python 3.x,luajit,cmake" shell
[python,luajit,cmake] $ python --version
Python 3.10.6
[python,luajit,cmake] $ cmake --version
cmake version 3.25.3
`
</code></pre>
<p>Xmake will automatically install the dependencies and open a new shell environment, which will also have a prompt on the left side of the terminal.</p>
<p>If we want to exit the current environment, we simply need to run</p>
<pre><code class="lang-console">[python,luajit,cmake] $ xrepo env quit
$
</code></pre>
<h3 id="showthegivenpackageinformation">Show the given package information</h3>
<pre><code class="lang-console">$ xrepo info zlib
The package info of project:
    require(zlib):
      -> description: A Massively Spiffy Yet Delicately Unobtrusive Compression Library
      -> version: 1.2.11
      -> urls:
         -> http://zlib.net/zlib-1.2.11.tar.gz
            -> c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
         -> https://downloads.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
            -> c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
      -> repo: xmake-repo https://gitee.com/tboox/xmake-repo.git master
      -> cachedir: /Users/ruki/.xmake/cache/packages/2010/z/zlib/1.2.11
      -> installdir: /Users/ruki/.xmake/packages/z/zlib/1.2.11/d639b7d6e3244216b403b39df5101abf
      -> searchdirs:
      -> searchnames: zlib-1.2.11.tar.gz
      -> fetchinfo: 1.2.11, system
          -> version: 1.2.11
          -> links: z
          -> linkdirs: /usr/local/Cellar/zlib/1.2.11/lib
          -> includedirs: /usr/local/Cellar/zlib/1.2.11/include
      -> platforms: iphoneos, mingw@windows, macosx, mingw@linux,macosx, android@linux,macosx, windows, linux
      -> requires:
         -> plat: macosx
         -> arch: x86_64
         -> configs:
            -> debug: false
            -> vs_runtime: MT
            -> shared: false
      -> configs:
      -> configs (builtin):
         -> debug: Enable debug symbols. (default: false)
         -> shared: Enable shared library. (default: false)
         -> cflags: Set the C compiler flags.
         -> cxflags: Set the C/C++ compiler flags.
         -> cxxflags: Set the C++ compiler flags.
         -> asflags: Set the assembler flags.
         -> vs_runtime: Set vs compiler runtime. (default: MT)
            -> values: {"MT","MD"}
</code></pre>
<h3 id="downloadpackagesourcecode">Download package source code</h3>
<p>We can use the <code>xrepo download</code> command to only download the source code of the specified package without installing it.</p>
<pre><code class="lang-bash">$ xrepo download zlib
$ xrepo download "zlib 2.x"
</code></pre>
<p>The default download directory is in the <code>packages</code> subdirectory of the current directory. We can also modify the download directory through the <code>-o outputdir</code> parameter.</p>
<pre><code class="lang-bash">$ xrepo download -o /tmp zlib
</code></pre>
</article>
</body>
</html>